/**
 * 
 */
package com.kexinde.wjifen.dao;

import java.util.List;

import com.kexinde.wjifen.model.Shop;
import com.kexinde.wjifen.util.JdbcTemplate;
import com.kexinde.wjifen.vo.SearchShop;

/**
 * 店铺数据库操作类
 * 
 * @author vincent
 * 
 */
public class ShopDao {

	/**
	 * 查询16个热门商店,index页显示
	 * 
	 * @return 热门商店集合，以注册资金排序
	 * @throws Exception
	 */
	public List<Shop> queryHostShops() throws Exception {
		String sql = "SELECT id,name,logo,profile FROM tb_shop ORDER BY"
				+ " regMoney DESC LIMIT ?,?";
		Object[] params = { 0, 16 };
		return JdbcTemplate.queryList("com.kexinde.wjifen.model.Shop", sql,
				params, 4);
	}

	/**
	 * 查询16个最新商店,index页显示
	 * 
	 * @return 热门商店集合，以注册时间排序
	 * @throws Exception
	 */
	public List<Shop> queryNewShops() throws Exception {
		String sql = "SELECT id,name,logo,profile FROM tb_shop ORDER BY"
				+ " insTime DESC LIMIT ?,?";
		Object[] params = { 0, 16 };
		return JdbcTemplate.queryList("com.kexinde.wjifen.model.Shop", sql,
				params, 4);
	}

	/**
	 * 查询16个个人最常去商家,index页显示
	 * 
	 * @return 最常去商家集合，以消费次数以及注册资金排序
	 * @throws Exception
	 */
	public List<Shop> queryMyHotShops(Long userId) throws Exception {
		String sql = "select id,name,logo,profile times from v_myhotshop where userId=? group by shopId"
				+ " order by count(*) desc , regMoney desc limit ?,?;";
		Object[] params = { userId, 0, 16 };
		return JdbcTemplate.queryList("com.kexinde.wjifen.model.Shop", sql,
				params, 4);
	}

	/**
	 * 根据店铺id查询店铺信息
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public Shop findById(Long id) throws Exception {
		String sql = "select id,name,email,telNum,logo,profile,addressId,regMoney,insTime,service,atmosphere,'character',businessHour,busInfo,map,tasteRank,environmentRank,serviceRank from tb_shop where id=?";
		Object[] params = { id };
		return JdbcTemplate.query("com.kexinde.wjifen.model.Shop", sql, params,18);
	}

}
